package controller;

import models.Audit;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import service.AuditService;
import service.UserService;
import service.impl.AuditServiceImpl;
import service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class ReportController {


    AuditService auditService = new AuditServiceImpl();
    UserService userService = new UserServiceImpl();

    @RequestMapping(value = "/report",method = RequestMethod.POST)
    public String reportPage(@RequestParam(name = "commentId") String commentId, HttpSession session) {
        // 在这里处理 commentId，进行举报相关的逻辑
        session.setAttribute("commentId",commentId);
        return "report"; // 返回举报页面的视图名
    }

    @RequestMapping(value ="/submitReportMsg",method = RequestMethod.POST)
    public void submitReport(HttpServletRequest request, HttpSession session)
    {
        Audit audit = new Audit();
        String type = request.getParameter("reportType");
        String reason = request.getParameter("reportReason");
        String name = (String) session.getAttribute("username");
        Integer userid = userService.getUseridByname(name);
        Integer tid = Integer.parseInt((String) session.getAttribute("commentid"));
        audit.setUid(userid);
        audit.setTid(tid);
        audit.setType(type);
        audit.setMsg(reason);
        auditService.addAudit(audit);
        session.removeAttribute("commentId"); // 清除名为commentId的属性


    }
}



